package com.wf.controller;

import cn.hutool.core.lang.Validator;
import com.wf.domain.BookingInfo;
import com.wf.exception.ApartmentException;
import com.wf.service.BookingInfoService;
import com.wf.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约接口
 * @author mpk
 * @since 2024/8/31 14:14:51
 */
@RestController
@RequestMapping("/app/booking")
public class BookingController {



    @Autowired
    BookingInfoService bookingInfoService;

    /**
     * 提交预约申请
     * @param bookingInfo
     * @return
     */
    @PostMapping("/commit")
    public Result insertBooking(@RequestBody BookingInfo bookingInfo) throws ApartmentException {

        if(!Validator.isMobile(bookingInfo.getPhone()))
        {
            throw new ApartmentException("请输入正确的手机号!");
        }

        boolean save = bookingInfoService.insertBooking(bookingInfo);
        if(!save)
        {
            return Result.failure("发起预约失败");
        }
        return Result.success("发起预约成功",null);

    }
    /**
     * 我的预约
     * @return
     */
    @DeleteMapping("/delete/{bookingId}")
    public Result deleteBookingById(@PathVariable String bookingId) {

        boolean b = bookingInfoService.removeById(bookingId);

        return Result.success(b);

    }

    /**
     * 我的预约
     * @return
     */
    @GetMapping("/get")
    public Result getBookingList() {

        List<BookingInfo> bookingInfo= bookingInfoService.getBooking();

        return Result.success(bookingInfo);

    }

}
